﻿using Microsoft.EntityFrameworkCore;
using Model.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace IDAL
{
    public interface IBaseDAL<T> where T : EntityBase
    {


        DbContext GetDbContext();

        /// <summary>
        /// 添加实体方法
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        bool CreateEntity(T entity);
        Task<bool> CreateEntityAsync(T entity);
        /// <summary>
        /// 批量插入实体返回受影响行数
        /// </summary>
        /// <param name="values"></param>
        /// <returns></returns>
        int CreateEntity(List<T> values);
        Task<int> CreateEntityAsync(List<T> values);
        /// <summary>
        /// 查询所有实体根据条件
        /// </summary>
        /// <returns></returns>
        IQueryable<T> GetEntities(Expression<Func<T, bool>> whereLambda);
        /// <summary>
        /// 更新实体对象
        /// </summary>
        /// <param name="entity">要更新的对象</param>
        /// <returns></returns>
        bool UpdateEntity(T entity);
        Task<bool> UpdateEntityAsync(T entity);
        /// <summary>
        /// 删除实体对象
        /// </summary>
        /// <param name="id">根据id</param>
        /// <returns></returns>
        bool DeleteEntity(int id);
        Task<bool> DeleteEntityAsync(int id);
        /// <summary>
        /// 删除实体对象
        /// </summary>
        /// <param name="entity">根据实体</param>
        /// <returns></returns>
        bool DeleteEntity(T entity);
        Task<bool> DeleteEntityAsync(T entity);
    }
}
